package com.ahstu.learning.SubjectActivity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ahstu.learning.R;

import java.util.ArrayList;

/**
 * Created by xuning on 2016/7/25.
 */
public class CourseAdapter extends BaseAdapter {
    ArrayList<Subject> list;
    
    private LayoutInflater inflater;
    ImageLoader imageLoader;
   public CourseAdapter(ArrayList list,Context context)
   {
       this.list=list;
       inflater = LayoutInflater.from(context);
       imageLoader=new ImageLoader();
       
       
   }
    
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        viewHolder holder = null;
        if (view == null) {
            holder = new viewHolder();
            view = inflater.inflate(R.layout.course_item, null);
            holder.txName = (TextView) view.findViewById(R.id.subject_name);
            holder.image = (ImageView) view.findViewById(R.id.head);
            // holder.btplay = (Button) view.findViewById(R.id.play);
            // holder.btReduce = (Button) view.findViewById(R.id.download);
            view.setTag(holder);
        } else {
            holder = (viewHolder) view.getTag();

        }
        holder.txName.setText(list.get(position).getCoursename());
        imageLoader.showAsytask(holder.image,list.get(position).getImageurl());
        return view;
    }
    class viewHolder
    {
        TextView txName;
        ImageView image;
        
        
    }
}
